﻿//----------------------------------------------------------------
// <copyright file="BLL_UserDetail.cs" >
//    Copyright (c) Wenzy , All rights reserved.
//    author:温正宇 E-Mail:wenzy@tom.com　MyBlog:wenzy.cnblogs.com
//    All rights reserved.
// </copyright>
//----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using MemberShipDAL.DataObject.DataUserDetailTableAdapters;
using MemberShipDAL.DataObject;

namespace MemberServerBLL
{
    public class BLL_UserDetail
    {
        /// <summary>
        /// 用DataTable返回用户所有的详细信息
        /// </summary>
        /// <param name="memberList"></param>
        /// <returns></returns>
        public MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailRow GetUserDetail(MembershipUser user)
        {
            return GetUserDetail(new Guid(user.ProviderUserKey.ToString()));
        }

        public MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailRow GetUserDetail(Guid userID)
        {
            MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailDataTable userDetail = new DataUserDetail.wmf_UserDetailDataTable();
            wmf_UserDetailTableAdapter da = new wmf_UserDetailTableAdapter();
            userDetail = da.GetDataByUserId(userID);
            if (userDetail.Rows.Count == 0) return null;
            if (userDetail.Rows.Count == 1)
            {
                return (MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailRow)userDetail.Rows[0];
            }
            else
            {
                throw new Exception("系统提示：用户Id重复，请检查");
            }
        }

        /// <summary>
        /// 用DataTable返回用户所有的详细信息
        /// </summary>
        /// <param name="memberList"></param>
        /// <returns></returns>
        public MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailDataTable GetUserDetail(MembershipUserCollection users)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// 更新用户详细信息
        /// </summary>
        /// <param name="dtUserDataTable"></param>
        /// <returns></returns>
        public int UpdateUserDetail(MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailDataTable dtUserDataTable)
        {
            wmf_UserDetailTableAdapter da = new wmf_UserDetailTableAdapter();
            int updateCont = da.Update(dtUserDataTable);
            return updateCont;
        }

        /// <summary>
        /// 更新用户详细信息,根据用户的GUID
        /// </summary>
        /// <param name="dtUserDataTable"></param>
        /// <returns></returns>
        public int UpdateUserDetail(System.Guid UserId, int UserNo, string NickName, string TrueName,
            bool? Sex, System.DateTime? BirthDay, string IdCard,
            string Country, string Province, string City, string Address, string Postcode,
            string Profession,
            decimal Account,
            string Signature, bool EnableSign,
            string Blog,
            string Interest,
            byte[] Images, string ImageType, bool EnableImage,
            string PrivateEmail, bool EnableReviceEmail,
            string QQ, string TelePhone, string MobilePhone, string Fax, string Department)
        {
            DataUserDetail.wmf_UserDetailRow userDetailRow = GetUserDetail(UserId);
            wmf_UserDetailTableAdapter da = new wmf_UserDetailTableAdapter();
            int updateCont;
            //如果不存在，则插入数据库
            if (userDetailRow == null)
            {
                updateCont = da.Insert(UserId, UserNo, NickName, TrueName, Sex,
                                         BirthDay, IdCard,
                                         Country, Province, City, Address, Postcode,
                                         Profession,
                                         Account,
                                         Signature, EnableSign,
                                         Blog,
                                         Interest,
                                         Images, ImageType, EnableImage,
                                         PrivateEmail, EnableReviceEmail, QQ, TelePhone, MobilePhone, Fax, Department);
            }
            else
            {

                /*userDetailRow.UserId = UserId;
                userDetailRow.UserNo = UserNo;
                userDetailRow.NickName = NickName;
                userDetailRow.TrueName = TrueName;
                userDetailRow.TrueName = Sex;
                userDetailRow.BirthDay = BirthDay;
                userDetailRow.IdCard = IdCard;
                userDetailRow.Country = Country;
                userDetailRow.Province = Province;
                userDetailRow.City = City;
                userDetailRow.Address = Address;
                userDetailRow.Postcode = Postcode;
                userDetailRow.Profession = Profession;
                userDetailRow.Account = Account;
                userDetailRow.Signature = Signature;
                userDetailRow.EnableSign = EnableSign;
                userDetailRow.Blog = Blog;
                userDetailRow.Interest = Interest;
                userDetailRow.Image = Images;
                userDetailRow.ImageType = ImageType;
                userDetailRow.EnableImage = EnableImage;
                userDetailRow.PrivateEmail = PrivateEmail;
                userDetailRow.EnableReviceEmail = EnableReviceEmail;
                userDetailRow.QQ = QQ;*/


                updateCont = da.UpdateByUserId(UserNo, NickName, TrueName, Sex,
                                         BirthDay, IdCard,
                                         Country, Province, City, Address, Postcode,
                                         Profession,
                                         Account,
                                         Signature, EnableSign,
                                         Blog,
                                         Interest,
                                         Images, ImageType, EnableImage,
                                         PrivateEmail, EnableReviceEmail, QQ, TelePhone, MobilePhone, Fax, Department, UserId);
            }

            return updateCont;



        }


        /// <summary>
        /// 删除用户的详细信息
        /// </summary>
        /// <param name="dtUserDataTable"></param>
        /// <returns></returns>
        public void DeleteUserDetail(System.Guid UserId)
        {
            MemberShipDAL.DataObject.DataUserDetail.wmf_UserDetailDataTable dtUserDataTable = new DataUserDetail.wmf_UserDetailDataTable();
            wmf_UserDetailTableAdapter da = new wmf_UserDetailTableAdapter();
            da.DeleteUserDetail(UserId);
        }

    }
}
